/*
Copyright 2007 Julian Asamer

This file is part of Fractalicious.

    Fractalicious is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Fractalicious is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Fractalicious.  If not, see <http://www.gnu.org/licenses/>.
*/

#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import "Tree.h"
#import "Vector.h"
#import "Dragable.h"

@implementation Tree

-(id) init {
	[super init];
	p = [[DragablePoint alloc] initWithx: 196.0f y: 256.0f];
	[p setDelegate: self];
	[p addMaximumDistance: 190 fromPoint: [[Point2D alloc] initWithx: 256 y: 256]]; 
	return self;
}

-(NSMutableArray *)getStartLines {
	NSMutableArray* lines = [[NSMutableArray alloc] initWithCapacity: 1];
	[lines addObject: 
		[[Line2D alloc] initWithpx: 256.0f py: 512.0f qx: 256.0f qy: 256.0f]
	];
	return lines;
}

-(NSMutableArray *)getTransformers {
	NSMutableArray* tf = [[NSMutableArray alloc] initWithCapacity: 1];

	[tf addObject: [[Transformer2D alloc] initWithp1: 
		[[[Point2D alloc] initWithx: 256.0f y: 512.0f] autorelease]
		q1: [[[Point2D alloc] initWithx: 256.0f y: 256.0f] autorelease]
		p2: [[[Point2D alloc] initWithx: 256.0f y: 256.0f] autorelease]
		q2: p] 
	];
	[tf addObject: [[Transformer2D alloc] initWithp1: 
		[[[Point2D alloc] initWithx: 256.0f y: 512.0f] autorelease]
		q1: [[[Point2D alloc] initWithx: 256.0f y: 256.0f] autorelease]
		p2: [[[Point2D alloc] initWithx: 256.0f y: 256.0f] autorelease]
		q2:	[[[Point2D alloc] initWithx: 256+(256-p->x) y: p->y] autorelease]
	]];
	
	return tf;
}

-(void) pointChanged {
	[delegate startRecalculation: 1];
}
-(void) pointMouseUp {
	[delegate startRecalculation: 0];
}


-(NSMutableArray *)getDragables {
	NSMutableArray* dg = [[NSMutableArray alloc] initWithCapacity: 1];
	[dg addObject: p];
	return dg;
}

-(id) delegate {
	return delegate;
}
-(void) setDelegate:(id) d {
	delegate = d;
}


@end